package com.br.natusport.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

import org.apache.http.client.ClientProtocolException;

import android.content.Context;
import android.net.ConnectivityManager;
import android.util.Log;
import android.widget.Toast;

public class ConnectionUtil {

	public static boolean isInternetCapable;
	public static boolean isConnected;

	public static String getResponseFromUrl(String addr) {

		try {
			return openURL(addr);
		} catch (Exception e) {
			return null;
		}
	}

	public static String getObjectFromUrl(String addr) {

		try {
			String json = openURL(addr);
			return json;
		} catch (Exception ex) {
			Log.e("Erro", ex.getMessage());
			return null;
		}
	}

	public static String openURL(String addr) throws Exception {
		
		String linha = "";
		try {
			URL url = null;
			url = new URL(addr);

			BufferedReader br = null;

			br = new BufferedReader(new InputStreamReader(url.openStream()));

			linha = br.readLine();
			br.close();

		} catch (ClientProtocolException e) {
			Log.e("WebService", e.toString());
		} catch (IOException e) {
			Log.e("WebService", e.toString());
		} catch (IndexOutOfBoundsException e) {
			Log.e("Index", e.toString());
		}
				
		return linha;
	}
}
